package priv.yiyuan.example.design.pay02;

/**
 * 信用卡支付
 *
 * @author YiYuan
 * @data 2025/8/8
 * @apoNote
 */
public class CreditCardPayment implements UnifiedPayment {

    private String cardNumber;

    private String cardHolder;

    public CreditCardPayment(String cardNumber, String cardHolder) {
        this.cardNumber = cardNumber;
        this.cardHolder = cardHolder;
    }

    @Override
    public void processPayment(double amount, String paymentDetails) {

        System.out.println(String.format("Processing credit card payment: $%.2f\n", amount));
        System.out.println("Card: " + maskCardNumber(cardNumber) + ", Holder: " + cardHolder);
        System.out.println("Payment details: " + paymentDetails);

    }

    private String maskCardNumber(String cardNumber) {
        return "****_****_****_" + cardNumber.substring(cardNumber.length() - 4);
    }

}
